<template>
	<!-- 登录 -->
	<view class="warp">
		<!-- #ifdef APP-PLUS -->
		<view class="title-contents"><view class="top-view status"></view></view>
		<!-- #endif -->
		<view class="login-title">
			<view class="logo"><image src="/static/images/common/logo.png" mode=""></image></view>
		</view>
		<view class="login-phone form-wapper">
			<view class="phone input-wapper">
				<view class="lside"><text class="iconfont icon-shouji"></text></view>
				<view class="mobile rside"><input placeholder-class="input-placeholder" type="number" placeholder="请输入手机号" v-model="username"/></view>
			</view>
			<view class="code input-wapper">
				<view class="lside"><text class="iconfont icon-mima2"></text></view>
				<view class="rside"><input placeholder-class="input-placeholder" type="password" maxlength="12" placeholder="请输入密码(6-12位) " v-model="password"/></view>
			</view>
			<view class="paw" @click="navTo('/pages/public/code_login')"><view class="btn">验证码登录</view></view>
		</view>

		<button type="primary" class="login-btn" @click="log">登录</button>
		<view class="reg-paw">
			<text class="active" @click="submit">注册账号</text>
			<text @click="navTo('/pages/public/forget')">忘记密码</text>
		</view>
		<!-- #ifdef APP-PLUS -->
		<view class="quick">
			<view class="quick-title">
				<text class="line"></text>
				<text class="txt">快捷登陆</text>
				<text class="line"></text>
			</view>
			<view class="sanfang"><image src="../../static/temp/share_wechat.png" mode=""></image></view>
		</view>
		<!-- #endif -->
	</view>
</template>
<script>
// import {mapMutations} from 'vuex'

export default {
	data() {
		return {
			username:'',
			password:'',
			host: 'https://4de16698-d9f4-443a-b416-ef1037cce952.bspapp.com/http'
		};
	},
	onLoad() {
		
	},
	methods: {
		// ...mapMutations(['login']),
		log() {
			console.log(this.username, this.password)
			if (this.username == "") {
				uni.$u.toast('手机号不能为空')
				return false
			}
			if (this.password == "") {
				uni.$u.toast('密码不能为空')
				return false
			}
			uni.request({
				url: this.host + '/user/login',
				method:'POST',
				data:{
					username:this.username,
					password:this.password
				},
				success: res => {
					console.log(res);
					uni.$u.toast(res.data.msg)
					if(res.data.code==0){
						uni.$u.toast('登陆成功')
						//登录功能必须要做token值
						// setItem('取的名字',把哪个值存进去)
						uni.setStorageSync('token',res.data.token)
						uni.setStorageSync('tokenExpired',res.data.tokenExpired)
						uni.setStorageSync('uid',res.data.uid)
						uni.setStorageSync("userInfo",JSON.stringify(res.data.userInfo))
						uni.setStorageSync("username",this.username)
						setTimeout(function(){
							uni.switchTab({
								url: '/pages/index/index',
							})
						},500)
					}
					
				},
				fail: () => {
					console.log(err)
					if(this.response.ststus==401){
						console.log('手机号或密码错误')
					}
					if(this.response.ststus==404){
						console.log('网络请求失败')
					}
				}
			});
		},
		submit(){
			uni.navigateTo({
				url:'/pages/public/reg'
			})
		}
	}
};
</script>
<style lang="scss">
@import 'login.scss';
</style>
